home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
httpd
/
cgi-src
/
annotate.c
next >
Wrap
C/C++ Source or Header
|
1995-05-09
|
3KB
|
116 lines
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#define MAX_ENTRIES 5
#define DOCUMENT_ROOT "/usr/ftp/pub"
/* where you want to log any annotations made, undefine to turn off logging */
#define LOGFILE "/usr/http/logs/annotate_log"
typedef struct {
char *name;
char *val;
} entry;
char *makeword(char *line, char stop);
char *fmakeword(FILE *f, char stop, int *len);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);
add_annotation(entry *entries)
{
FILE *fp;
char filename[256];
time_t clock;
sprintf(filename,"%s/annotations/%s",DOCUMENT_ROOT,entries[1].val);
fp = fopen(filename, "a");
if (fp != NULL)
{
clock=time(0) ;
fprintf(fp, "<H3><HR>Annotation by %s at %s</H3>\n",entries[0].val,ctime(&clock));
fprintf(fp, "%s",entries[2].val);
}
fclose(fp) ;
#ifdef LOGFILE
fp = fopen(LOGFILE, "a");
if (fp != NULL)
{
fprintf(fp, "\n-----------------------------------------------------\n");
fprintf(fp, "%s: %s at %s\n",filename,entries[0].val,ctime(&clock));
fprintf(fp, "%s",entries[2].val);
}
fclose(fp) ;
#endif
}
main(int argc, char *argv[]) {
entry entries[MAX_ENTRIES];
register int x,m=0;
int cl;
char filename[256];
char line[256];
FILE *fp;
printf("Content-type: text/html%c%c",10,10);
if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
printf("This script should be referenced with a METHOD of POST.\n");
printf("If you don't understand this, see this ");
printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
exit(1);
}
if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
printf("This script can only be used to decode form results. \n");
exit(1);
}
cl = atoi(getenv("CONTENT_LENGTH"));
for(x=0;cl && (!feof(stdin));x++) {
m=x;
entries[x].val = fmakeword(stdin,'&',&cl);
plustospace(entries[x].val);
unescape_url(entries[x].val);
entries[x].name = makeword(entries[x].val,'=');
}
if (entries[0].val[0] == '\0') {
printf("<TITLE>Annotation error</TITLE>\n") ;
printf("<H1>Annotation error</H1>\n") ;
printf("You did not enter a login! Please go back and try again.\n") ;
exit(0) ;
}
if (entries[2].val[0] == '\0') {
printf("<TITLE>Annotation error</TITLE>\n") ;
printf("<H1>Annotation error</H1>\n") ;
printf("You did not enter any comments! Please go back and try again.\n") ;
exit(0) ;
}
add_annotation(entries) ;
sprintf(filename,"%s/annotations/%s",DOCUMENT_ROOT,entries[1].val);
fp = fopen(filename, "r");
if (fp != NULL)
{
while (fgets(line, 256, fp)!=NULL)
printf("%s",line) ;
}
fclose(fp) ;
}